package com.ytjj.quartz.service;

import com.ytjj.qmyx.mall.mapper.OrdersSendRecordMapper;
import com.ytjj.qmyx.mall.model.OrdersSendRecord;
import com.ytjj.qmyx.mall.model.OrdersSendRecordExample;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@Slf4j
public class YxOrdersSendRecordService {
    @Resource
    private OrdersSendRecordMapper ordersSendRecordMapper;

    public boolean insert(OrdersSendRecord record) {
        int result = ordersSendRecordMapper.insert(record);
        return result > 0 ? true : false;
    }

    /**
     * 查询发送记录
     * @param orderinfoId
     * @param type 1-创建订单 2-支付订单
     * @return
     */
    public int queryByOrderInfoId(Integer orderinfoId,Integer type) {
        OrdersSendRecordExample ordersSendRecordExample=new OrdersSendRecordExample();
        ordersSendRecordExample.setOrderByClause("id desc");
        ordersSendRecordExample.createCriteria().andOrderinfoIdEqualTo(orderinfoId)
                .andTypeEqualTo(type.byteValue());
        List<OrdersSendRecord> sendRecordList=ordersSendRecordMapper.selectByExample(ordersSendRecordExample);
        if(sendRecordList!=null){
            return sendRecordList.size();
        }
        return 0;
    }
}
